<template>
	<gui-page ref="guiPage" :customHeader="true">
		<!-- 导航 -->
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :leftType="'1'" @clickLeftBack="clickLeftBack"
				:title="$t('pageTranslation.rMTransfer')" @clickRight="clickRight" scanType="1"></nav-bar-custom>
		</template>

		<template v-slot:gBody>
			<view class="barcodeSplitting">
				<!-- 扫描和库位选择模块 -->
				<view class="custom-form-card">
					<view class="custom-card-title">
						<text class="title-line"></text>
						{{ $t('distributedEnter.barcodeScan') }}
					</view>
					<view class="custom-card-itemTwo" style="padding: 20rpx 0">
						<text class="item-info-title">{{ $t('translationImage.bringUpWarehouse') }}：</text>
						<!-- <input type="text" disabled style="margin: 8rpx 0;text-align: right;" class="gui-form-input" v-model="data.outWarehouseCodeText" :placeholder="$t('pageTranslation.defaultLocationBy')" /> -->
						<superweiCombox style="text-align:right;" :candidates="data.materialWarehouse"
							:placeholder="$t('distributedOut.placeholder')" :isJSON="true" keyName="text"
							v-model="data.outWarehouseName" @select="materialWarehouseSelect"></superweiCombox>
					</view>
					<!-- 调入仓库 -->
					<view class="custom-card-itemTwo" style="padding: 20rpx 0;">
						<text class="item-info-title">{{ $t('translationImage.transferredWarehouse') }}：</text>
						<superweiCombox style="text-align:right;" :candidates="data.materialTransferListIn"
							:placeholder="$t('distributedOut.placeholder')" :isJSON="true" keyName="value"
							v-model="data.warehouseText" @select="materialTransferSelect"></superweiCombox>
					</view>
					<!-- 库位 -->
					<view v-if="data.isCapacityBool" class="custom-card-itemTwo" style="padding: 20rpx 0;">
						<text class="item-info-title"><text
								class="required-color">*</text>{{ $t('translationImage.transferredSeat') }}：</text>
						<storageBin ref="storageBinRef" v-model="data.defaultValue"
							:ignoreLocationCode="data.ignoreLocationCode" class="gui-text-right"
							requestUrl="/wms/wmsLocationCapacity/getLocationByWarehouseCodeForCCP"
							:requestParam="data.requestParam" @setClick="getClick"></storageBin>
					</view>
					<view v-else class="custom-card-itemTwo" style="padding: 20rpx 0;">
						<text class="item-info-title"><text
								class="required-color">*</text>{{ $t('translationImage.transferredSeat') }}：</text>
						<comboGrid ref="comboGridRef" v-model="data.defaultValue" :requestParam="data.requestParam"
							requestUrl="/wms/wmsLocationCapacity/getLocationByWarehouseCodeForCCP"
							:placeholder="$t('distributedEnter.placeholderTextChoose')" inputKey="locationCode"
							:column="data.columnRule.column" bindValue="locationCode" @setClick="getClick"></comboGrid>
					</view>
					<view class="custom-card-itemTwo" style="padding: 20rpx 0;">
						<text class="item-info-title" style="padding-right: 40rpx;"><text
								class="required-color">*</text>{{ $t('warehousing.transferType') }}：</text>
						<radio-group @change="radioChange" class="group">
							<label class="uni-list-cell uni-list-cell-pd group-label" v-for="(item, index) in data.items" :key="item.value">
								<view class="lable-view">
									<radio :value="item.value" :checked="index === data.current"  />
								</view>
								<view>{{item.name}}</view>
							</label>
						</radio-group>
					</view>
					<view class="custom-card-itemTwo" style="padding: 20rpx 0;">
						<text class="item-info-title" style="padding-right: 40rpx;"><text
								class="required-color">*</text>{{ $t('distributedEnter.barcodeScan') }}：</text>
						<uni-easyinput class="uni-mt-5" suffixIcon="scan" v-model="data.barcode" type="search"
							@confirm="confirm" @iconClick="iconClick"
							:placeholder="$t('translationImage.pleaseScanTray')">
						</uni-easyinput>
					</view>
				</view>
				<!-- card模块 -->
				<!-- <scroll-view :show-scrollbar="false" :scroll-y="true" class="scroll"> -->
				<view v-if="data.scanInfo" class="custom-form-card">
					<uni-collapse v-model="data.value">
						<uni-collapse-item titleBorder="none" :show-animation="true">
							<template v-slot:title>
								<view class="custom-card-title">
									<text class="title-line"></text>
									{{ $t('distributedOut.atPresent') }}
								</view>
							</template>
							<view class="content">
								<view class="custom-card-itemOne item-color" style="color: red;">
									<text class="item-info-title item-color" style="color: red;">{{ $t('materials.todaysRecommendedDosage') }}：</text>{{(data.scanInfo.standardDosage||0)}}
								</view>
								<view class="custom-card-itemOne item-color" style="color: red;">
									<text class="item-info-title item-color" style="color: red;">{{ $t('materials.todaysRecommendedBarCode') }}：</text>{{(data.scanInfo.barcodeNum)}}
								</view>
								<view class="custom-card-itemOne">
									<text class="item-info-title">{{ $t('distributedEnter.materialCoded') }}：</text>{{data.scanInfo.barcode}}
								</view>
								<view class="custom-card-itemOne">
									<text class="item-info-title">{{ $t('distributedEnter.materialCode') }}：</text>{{data.scanInfo.materialCode
									}}
								</view>
								<view class="custom-card-itemOne">
									<text class="item-info-title">{{ $t('distributedEnter.materialName') }}：</text>{{data.scanInfo.materialName}}
								</view>
								<view class="custom-card-itemOne">
									<text class="item-info-title">{{ $t('distributedEnter.materialSpec') }}：</text>{{data.scanInfo.materialSpec}}
								</view>
								<view class="custom-card-itemOne">
									<view class="card-item-50">
										<text class="item-info-title">{{ $t('distributedEnter.qty') }}：</text>{{data.scanInfo.currentQty}}
									</view>
									<view class="card-item-50">
										<text class="item-info-title">{{ $t('distributedEnter.uom') }}：</text>{{data.scanInfo.unit}}
									</view>
								</view>
								<view class="custom-card-itemOne" v-if="data.transferType!='all'">
									<text class="item-info-title">{{ $t('warehousing.transferQty')}}：</text>{{(data.scanInfo.changeQty||0)}}
								</view>
								<view class="custom-card-itemOne">
									<text class="item-info-title">{{ $t('translationImage.process') }}：</text>{{data.scanInfo.processCode}}
								</view>
							</view>
						</uni-collapse-item>
					</uni-collapse>
				</view>
				<!-- </scroll-view> -->

				<!-- 底部确定按钮 -->
				<view class="page-bottom-box bottom-postion">
					<view class="page-bottomBtn" @click="recommended" style="background-color:#3598DC;color:#fff;">{{ $t('materials.todaysRecommendedDosage') }}</view>
					<view class="page-bottomBtn bottomBtn-bgcolor-green" @click="handelCommit">{{ $t('calendar.submit') }}</view>
				</view>
				<!-- 页面弹框 -->
				<uni-popup ref="inputDialog" type="center" :mask-click="false">
					<view class="input-dialog-box">
						<view class="input-dialog-content">
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialCode')}}:{{data.scanInfo.materialCode}}
							</view>
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialName')}}:{{data.scanInfo.materialName}}
							</view>
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialSpec')}}:{{data.scanInfo.materialSpec}}
							</view>
							<view class="input-dialog-item flexclass">
								<view>{{$t("materials.scanQty")}}：</view>
								<view class="input-dialog-item-count">
									<input v-model="data.inputCurrentQty" type="number"
										:placeholder="$t('distributedEnter.pleaseMaterialQty')" @confirm="qtyInput" />
								</view>
							</view>
						</view>
						<view class="input-dialog-footer">
							<view class="input-dialog-button" @click="cancelFn">
								{{$t('calendar.cancel')}}
							</view>
							<view class="input-dialog-button dialog-button-left" @click="confirmFn">
								{{$t('calendar.confirm')}}
							</view>
						</view>
					</view>
				</uni-popup>
				<!-- 调拨的弹框 -->
				<uni-popup ref="inputSplitDialog" type="center" :mask-click="false">
					<view class="input-dialog-box">
						<view class="input-dialog-content">
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialCode')}}:{{data.scanInfo.materialCode}}
							</view>
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialName')}}:{{data.scanInfo.materialName}}
							</view>
							<view class="input-dialog-item">
								{{$t('distributedEnter.materialSpec')}}:{{data.scanInfo.materialSpec}}
							</view>
							<view class="input-dialog-item">
								<text class="item-info-title">{{ $t('distributedEnter.qty') }}：</text>{{data.scanInfo.currentQty}}
							</view>
							<view class="input-dialog-item flexclass" style="padding: 20rpx 0;">
								<text class="item-info-title" style="padding-right: 40rpx;"><text
										class="required-color">*</text>{{ $t('warehousing.transferQty') }}：</text>
								<uni-easyinput class="uni-mt-5" v-model="data.changeQty" type="number"
									:placeholder="$t('hardwareOut.pleaseQty')">
								</uni-easyinput>
							</view>
						</view>
						<view class="input-dialog-footer">
							<!-- <view class="input-dialog-button" @click="cancelFnSplit">
								{{$t('calendar.cancel')}}
							</view> -->
							<view class="input-dialog-button dialog-button-left" @click="confirmFnSplit">
								{{$t('calendar.confirm')}}
							</view>
						</view>
					</view>
				</uni-popup>
			</view>
		</template>
	</gui-page>
</template>

<script setup>
import { navigate, navigateBack } from '@/utils/routerSkip.js';
import { getDataDictionaryFn, pitchOnFn } from '@/utils/index.js'
import comboGrid from '@/components/comboGrid.vue'
import pdaScan from '@/hooks/pdaScan.js'
import { useStore } from "vuex";
import storageBin from '@/components/storageBin.vue'
import superweiCombox from '@/components/superweiCombox';
import { materialTransfer, wmsSelectWmsBarcodeInfo, saveInputRecord, getCurrentUser, getDataDictionary } from '@/api/api.js'
import { USERINFO, OPERATION_COMMIT, OPERATION_SCAN } from '@/constant/index.js'
import { basPdaOperationLogFn } from '@/utils/index.js';
import { onBackPress } from '@dcloudio/uni-app';
import {
	ref,
	reactive,
	onMounted,
	watch,
	computed,
	toRaw
} from 'vue';

//JS国际化引入
import { useI18n } from 'vue-i18n';
const { t } = useI18n();

let inputDialog = ref(null)
let inputSplitDialog= ref(null)

components: {
	superweiCombox,
		storageBin,
		comboGrid
}
const storageBinRef = ref(null)
const comboGridRef = ref(null)
let data = reactive({
	defaultValue: '',
	isCapacityBool: false,// 是否带容量 默认为false
	value: ['0'],
	requestParam: {
		warehouseCode: ''
	},
	barcodeList: [],//扫描的条码数组
	locationUseList: [],//
	scanInfo: undefined,
	ignoreLocationCode: [], //前端算满的库位
	materialTransferList: [],//调入仓库数据
	materialTransferListIn: [],
	materialWarehouse: [],//调出仓库数据
	outWarehouseCodeText: '',//'原材料仓'
	outWarehouseCode: '',//'RM'
	outWarehouseName: "",//调出仓库
	warehouseText: '',//调入仓库
	locationId: '',// 调入库位
	warehouseCode: '',//仓库code
	barcode: '', //条码
	currentSeat: '', //调入库位
	enterWarehouse: '',//调入仓库
	columnRule: {
		column: [{
			label: t('distributedOut.location'),
			name: "locationCode",
		}]
	},
	userInfo: {},
	inputCurrentQty:null,// 特殊条码的数量
	changeQty:0, //拆分条码数量
	items:[{
            value: 'section',
            name: t('warehousing.partialAllocation'),
            checked: 'true'
        },
        {
            value: 'all',
            name: t('warehousing.fullAllocation')
        }],
	current: 0,
	transferType:'section',//拆分类型
	splitStatus:false
})
let store = useStore();
const { scan } = pdaScan()
onMounted(() => {
	console.log('开始监听PDA扫码')
	uni.$on('scancodedate', (data) => {
		console.log('获取到的code：' + data.code)
		getCode(data.code, 'pda')
	})
	getInitData()

	//获取当前用户信息
	if (!uni.getStorageSync(USERINFO)) {
		requestUser()
	} else {
		data.userInfo = uni.getStorageSync(USERINFO)
	}
})
data.barcodeList = computed(() => {
	return store.state.allotList
})
// 计算库位逻辑
const calculateLocationCode = (newVal) => {
	let tepData = toRaw(newVal)
	if (!tepData.length) {
		data.scanInfo = undefined
	}
	if (!data.scanInfo && tepData.length) {
		data.scanInfo = tepData[0]
	}
	// 先清空,后续追加
	data.locationUseList.forEach(l => {
		l.barcodeList = []
	})
	// 追加
	tepData.forEach(x => {
		data.locationUseList.forEach(k => {
			if (x.locationCode == k.locationCode) {
				k.barcodeList.push(x.barcode)
				k.surplusCapacity = k.currentCapacity - k.barcodeList.length
			}
		})
	})
	if (!data.isCapacityBool) return
	//算满库位变量置空
	data.ignoreLocationCode = []
	// 把前端预算容量算出为0的库位抽出
	data.locationUseList.forEach(x => {
		if (x.surplusCapacity == 0) {
			data.ignoreLocationCode.push(x.locationCode)
		}
	})
	console.log(data.locationUseList, 'data.locationUseList')
	console.log(data.ignoreLocationCode, 'data.ignoreLocationCode')
}
const filter = async () => {
	// 查询目的仓库
	let locationCapacity = await getDataDictionaryFn('LocationCapacity')
	let bool = locationCapacity.some((item) => {
		return item.value == data.warehouseCode
	})
	data.isCapacityBool = bool
}
watch(() => data.warehouseCode, (newVal, oldVal) => {
	filter()
}, {
	immediate: true,
	deep: true
});
//把扫描条码变为物料集合的二维数组
watch(() => data.barcodeList, (newVal, oldVal) => {
	console.log('newVal, oldVal', newVal, oldVal)
	calculateLocationCode(newVal)
}, {
	immediate: true,
	deep: true
});
onBackPress((options) => {
	if (options.from == 'backbutton') {
		if (!data.barcodeList.length) {
			uni.navigateBack({
				delta: 1
			});
			return true
		}
		uni.showModal({
			title: t('smashRemoval.warmPrompt'),
			content: t('materials.unsubmittedDataIn'),
			success: function (res) {
				if (res.confirm) {
					store.commit('reactAllotList')
					uni.navigateBack({
						delta: 1
					});
				} else if (res.cancel) {
					console.log('用户点击取消');
				}
			}
		});
		return true;
	}
})
//导航栏左侧返回
const clickLeftBack = () => {
	if (!data.barcodeList.length) {
		uni.navigateBack({
			delta: 1
		});
		return
	}
	uni.showModal({
		title: t('smashRemoval.warmPrompt'),
		content: t('materials.clearedIfReturned'),
		success: function (res) {
			if (res.confirm) {
				store.commit('reactAllotList')
				uni.navigateBack({
					delta: 1
				});
			} else if (res.cancel) {
				console.log('用户点击取消');
			}
		}
	});
}

// 调出仓库获取
const outWarehouse = async () => {
	//新调出仓库的获取
	await getDataDictionary({
		code: 'TransferDirection',
		language: false
	}).then(res => {
		data.materialWarehouse = res;
		for (let i = 0; i < data.materialWarehouse.length; i++) {
			for (let j = i + 1; j < data.materialWarehouse.length; j++) {
				if (data.materialWarehouse[i].text == data.materialWarehouse[j].text) {
					data.materialWarehouse.splice(j, 1);
					j--
				}
			}
		}
		if (data.materialWarehouse.length) {
			data.outWarehouseName = data.materialWarehouse[0].text
			data.outWarehouseCode = data.outWarehouseName; //调出仓库给code赋值
			data.locationId = "";
			data.defaultValue = ""
			data.materialTransferListIn = []; //给调入仓库清空在赋值与调出仓库一致的给到数组
			for (let i = 0; i < data.materialTransferList.length; i++) {
				if (data.materialTransferList[i].text == data.outWarehouseName) {
					data.materialTransferListIn.push(data.materialTransferList[i])
				}
			}
			if (!data.materialTransferListIn.length) return
			data.warehouseText = data.materialTransferListIn[0].value;
			data.requestParam.warehouseCode = data.materialTransferListIn[0].value  // 默认选中第一个 value
			data.warehouseCode = data.materialTransferListIn[0].value

		}
	});
}

const getInitData = async () => {
	// 获取领料人数据
	data.materialTransferList = await getDataDictionary({
		code: 'TransferDirection',
		language: false
	})
	let tepSelect1 = pitchOnFn(data.materialTransferList)
	outWarehouse()
	if (!tepSelect1.length) return
	data.requestParam.warehouseCode = tepSelect1[0].value  // 默认选中第一个 value
	data.warehouseCode = tepSelect1[0].value
}

// 调出仓库选择之后去判断获取对应的调入仓库
const materialWarehouseSelect = (e) => {
	data.outWarehouseCode = data.outWarehouseName; //调出仓库给code赋值
	data.warehouseText = "";//清空调入库位
	data.locationId = "";
	data.defaultValue = ""
	// console.log(e)
	data.materialTransferListIn = []; //给调入仓库清空在赋值与调出仓库一致的给到数组
	for (let i = 0; i < data.materialTransferList.length; i++) {
		if (data.materialTransferList[i].text == data.outWarehouseName) {
			data.materialTransferListIn.push(data.materialTransferList[i])
		}
	}
	if (!data.materialTransferListIn.length) return
	data.warehouseText = data.materialTransferListIn[0].value;
	data.requestParam.warehouseCode = data.materialTransferListIn[0].value
	data.warehouseCode = data.materialTransferListIn[0].value
}
// 选择仓库 取出相对的库位code
const materialTransferSelect = (e) => {
	console.log(e);
	data.requestParam.warehouseCode = e.value
	data.warehouseCode = e.value
	data.value = ['0']
	data.ignoreLocationCode = []
	data.locationId = ''
	data.defaultValue = ""
	if (data.isCapacityBool) {
		storageBinRef.value.restInitData()
	} else {
		comboGridRef.value.restInitData()
	}
}
// 用户点击扫码图标
const iconClick = async (type) => {
	if (type === 'suffix') {
		let code = await scan()
		getCode(code, 'scan')
	}
}
// 用户点击搜索
const confirm = () => {
	getCode(data.barcode, 'keydown')
}
// 获取选中的库位id
const getClick = (x) => {
	console.log(x)
	data.currentLocationInfo = x;
	data.locationId = x.locationCode;
}
// 获取code
const getCode = (code, type) => {
	data.changeQty=0
	if(!data.currentLocationInfo)
	{
		uni.showToast({
			title:t('Common.pleaseSelectLocation'),
			icon: 'none'
		})
		return
	}
	console.log(code, '---code---')
	// 判断这个托盘本次有没有绑定过
	console.log(data.barcodeList, 'data.barcodeList')
	let isBind = data.barcodeList.some(x => x.barcode == code);
	if (isBind) {
		uni.showToast({
			title: t('JsInternational.scanned'),
			icon: 'none'
		})
		return
	}
	if (!data.warehouseText) {
		uni.showToast({
			title: t('pageTranslation.plsChooseWarehous'),
			icon: 'none'
		})
		return
	}
	// 判断当前用户选择的库位有没有容量
	if (data.isCapacityBool && data.ignoreLocationCode.includes(data.locationId)) {
		uni.showToast({
			title: t('JsInternational.volumn'),
			icon: 'none'
		})
		return
	}
	if (!code) {
		uni.showToast({
			title: t('stockManage.pleaseScanCode'),
			icon: 'none'
		})
		return
	}
	data.scanValue = code
	let parmes = {
		isSp: 'N',
		warehouseCode: data.outWarehouseCode,
		barcode: code,
		selectType: 'materialTransfer',
	}
	wmsSelectWmsBarcodeInfo(parmes).then(res => {
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '原材料调拨'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.status,//返回状态
				errorMessage: res.message,//错误信息
				isPass: res.status == 200 ? 'Y' : 'N',//是否成功 Y N
				operationType: OPERATION_SCAN
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) {
		}
		console.log(res)
		if (res.status == 200) {
			// 判断当前扫描的barcode 是否存在扫描记录里面 如果存在 提示已扫描
			let isBind = data.barcodeList.some(x => x.barcode == res.data.barcode);
			if (isBind) {
				uni.showToast({
					title: t('pageTranslation.theBarcodeAlready'),
					icon: 'none'
				})
				return
			}
			data.scanInfo = res.data
			data.scanInfo.goalWarehouseCode = data.warehouseCode
			data.scanInfo.goalLocationCode = data.currentLocationInfo.locationCode
			data.scanInfo.goalLocationName = data.currentLocationInfo.locationName
			data.scanInfo.goalWarehouseName = '原材料仓'
			// 添加调拨类型和数量
			data.scanInfo.transferType=data.transferType
			if(data.transferType=='section'){
				inputSplitDialog.value.open();
				data.splitStatus=true
			}
			// 特殊的4个条码打开弹框
			if(code=='COVERPLATECARD-CHINA'||code=='PALLETCARD-CHINA'||code=='COVERPLATECARD-USA'||code=='PALLETCARD-USA'){
				inputDialog.value.open();
			}
			judgeBarcode()
		} else {
			data.scanInfo = undefined
			uni.showToast({ title: res.message, icon: "none" });
		}
	})
}

// 弹框的取消按钮
const cancelFn = () => {
		inputDialog.value.close();
		data.scanInfo= undefined
}
// 弹框确定按钮
const confirmFn=()=>{
	if(data.inputCurrentQty==null){
		uni.showToast({
			title: t('Common.pleaseFillInTheBarcode'),
			icon: 'none'
		})
		return
	}
	if(data.inputCurrentQty>Number(data.scanInfo.currentQty)){
		uni.showToast({
			title: t('Common.theEnteredNumberCannot'),
			icon: 'none'
		})
		return
	}
	data.scanInfo.currentQty=Number(data.inputCurrentQty)
	inputDialog.value.close();
}

// 调拨的弹框确定和取消
const cancelFnSplit = () => {
	inputSplitDialog.value.close();
		data.scanInfo= undefined
}
const confirmFnSplit=()=>{
	if(Number(data.changeQty)==null||Number(data.changeQty)<=0){
		uni.showToast({
			title: t('Common.pleaseFillInTheBarcode'),
			icon: 'none'
		})
		return
	}
	if(Number(data.changeQty)>Number(data.scanInfo.currentQty)){
		uni.showToast({
			title: t('Common.theEnteredNumberCannot'),
			icon: 'none'
		})
		return
	}
	data.scanInfo.changeQty=Number(data.changeQty)
	inputSplitDialog.value.close();
}

// 今日推荐用量获取
// 判断 Barcode
const judgeBarcode = () => {
	let isTrue = data.locationUseList.some(x => x.locationCode === data.locationId)
	if (!isTrue) {
		data.locationUseList.push({
			locationCode: data.currentLocationInfo.locationCode, //库位code
			surplusCapacity: Number(data.currentLocationInfo.maxCapacity) - Number(data.currentLocationInfo.usedInventory), //后端告诉前端容量
			barcodeList: [], //当前库位本次扫描绑定的barcode条码集合
			currentCapacity: Number(data.currentLocationInfo.maxCapacity) - Number(data.currentLocationInfo.usedInventory), //后端容量减去本次扫描绑定条码的剩余容量  前端预算容量
		})
	}
	store.commit('addAllotList', data.scanInfo)
}
//扫描纪录
const clickRight = () => {
	navigate({
		url: '/pages/barcodeManagement/allocationMaterialRecord'
	})
}
//获取当前用户信息
const requestUser = async () => {
	let res = await getCurrentUser({})
	if (res) {
		data.userInfo = res
		uni.setStorageSync(USERINFO, data.userInfo);
	}
}

// 提交操作
const handelCommit = () => {
	if (!data.barcodeList.length) {
		uni.showToast({
			title: t('stockManage.pleaseScanCode'),
			icon: 'none'
		})
		return
	}
	let tepData = toRaw(data.barcodeList)
	console.log(tepData, '----tepData----')
	let parmes = {
		oldWarehouseCode: data.outWarehouseName,//调出仓库
		warehouseCode: data.warehouseCode,//调入仓库
		wmsBarcodeList: []
	}
	//新添加提交接口的传参数
	let MesInputRecordVoList = []
	//新增mesInputProduceRelationVoList参数
	let mesInputProduceRelationVoList =[]
	tepData.forEach(x => {
		console.log(x)
		parmes.wmsBarcodeList.push({
			id: x.id,// 条码的id
			barcode: x.barcode,
			locationCode: x.goalLocationCode,// 仓库code
			warehouseCode: x.goalWarehouseCode,
			changeQty:x.changeQty,//拆分数量（调拨数量）
			transferType:x.transferType//拆分类型（调拨类型）
		});
		MesInputRecordVoList.push({
			barCode: x.barcode,
			materialCode: x.materialCode,
			operatorName: data.userInfo.userName,
			operatorNo: data.userInfo.userNameId,
			processCode: x.processCode,
			processName: x.processName,
			qty: Number(x.currentQty),
			sourceLocationCode: x.locationCode,
			sourceWarehouseCode: x.warehouseCode,
			targetLocationCode: x.goalLocationCode,
			targetWarehouseCode: x.goalWarehouseCode
		})
		mesInputProduceRelationVoList.push({
			inputBarcode: x.barcode,
			materialCode: x.materialCode,
			operatorName: data.userInfo.userName,
			operatorNo: data.userInfo.userNameId,
			processCode: x.processCode,
			processName: x.processName,
			qty: Number(x.currentQty),
			sourceLocationCode: x.locationCode,
			sourceWarehouseCode: x.warehouseCode,
			targetLocationCode: x.goalLocationCode,
			targetWarehouseCode: x.goalWarehouseCode
		})
		parmes.mesInputRecordVoList = MesInputRecordVoList
		parmes.mesInputProduceRelationVoList = mesInputProduceRelationVoList
		
	});
	// 添加加载框
	uni.showLoading({
		title: 'loading',
		mask: true
	});
	//提交接口
	materialTransfer(parmes).then(res => {
		try {
			let inputParameter = JSON.stringify(parmes)
			let returnParameter = JSON.stringify(res)
			let operationPicture = '原材料调拨'
			let callInterface = res.rquestUrl
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: res.status,//返回状态
				errorMessage: res.message,//错误信息
				isPass: res.status == 200 ? 'Y' : 'N',//是否成功 Y N
				operationType: OPERATION_COMMIT
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) {
		}
		console.log(res)
		if (res.status == 200) {
			tepData.forEach(x => {
				if(Number(x.changeQty)>0){
					store.commit('addAllotListSplit',x)
				}
			})
			//隐藏加载框
			uni.hideLoading();
			//删除已提交的数据
			uni.showToast({ title: t('smashRemoval.submitSuccessfully'), icon: "none" });
			store.commit('reactAllotList')
			// 清空数据
			data.outWarehouseName = "";
			data.warehouseText = "";
			data.defaultValue = "";
			data.barcode = "";
			data.inputCurrentQty=null;  //特殊条码数量置为0
			data.changeQty=0
			if(data.splitStatus){
				navigate({
				url: '/pages/barcodeManagement/allocationMaterialPrint'
			})
			}
			if (data.isCapacityBool) {
				storageBinRef.value.restInitData()
			} else {
				comboGridRef.value.restInitData()
			}
		} else {
			uni.showToast({ title: res.message, icon: "none" });
			return
		}
	});
	// 提交新添加的调用接口
	// saveInputRecord(MesInputRecordVoList).then(res=>{
	// 	if (res.status == 200) {
	// 		console.log(res.data)
	// 	}
	// })

}

const radioChange = (evt) => {
	// console
	for (let i = 0; i < data.items.length; i++) {
		if (data.items[i].value === evt.detail.value) {
			data.current = i;
			console.log(data.items[i])
			data.transferType=data.items[i].value
			break;
		}
	}
}

const recommended =()=>{
	navigate({
		url: '/pages/barcodeManagement/allocationMaterialRecommend'
	})
}
</script>

<style lang="scss" scoped>
.barcodeSplitting {
	display: flex;
	flex-direction: column;
	height: calc(100vh - 88rpx);
	// height: 100vh;
}

.distributed-head {
	border-bottom-left-radius: 16rpx;
	border-bottom-right-radius: 16rpx;
}

.scroll {
	flex: 1;
	height: 2rpx;
}

.page-bottom-box {
	position: absolute;
	left: 0px;
	bottom: 0px;
	width: 100%;
}
.item-color{
	color:#000;
	font-weight: bold;
}

.group{
	display: flex;
	flex-direction: row;
	.group-label{
		width: 230rpx;
		display: flex;
		flex-direction: row;
	}
	.lable-view{
		width:70rpx;
		height: 100%;
	}
}

</style>
